package cn.tedu.charging.device.dao.impl;

import cn.tedu.charging.device.dao.repository.StationCachRepository;
import cn.tedu.charging.device.pojo.po.StationPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.core.BoundGeoOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;


@Repository
public class StationCachRepositoryImpl implements StationCachRepository {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void saveStation2Redis(StationPO stationPO) {
        BoundGeoOperations stations = redisTemplate.boundGeoOps("stations");
        //获取经度
        BigDecimal stationLng = stationPO.getStationLng();
        //获取纬度
        BigDecimal stationLat = stationPO.getStationLat();

        Point point = new Point(Double.valueOf(stationLng.toEngineeringString()),
                Double.valueOf(stationLat.toEngineeringString()));

        stations.add(point, stationPO);
    }
}
